/*      */ package hmc;
/*      */ 
/*      */ import Serialio.SerialPortLocal;
/*      */ import java.awt.Container;
/*      */ import java.awt.event.ActionEvent;
/*      */ import java.awt.event.ActionListener;
/*      */ import java.awt.event.MouseAdapter;
/*      */ import java.awt.event.MouseEvent;
/*      */ import java.util.Set;
/*      */ import java.util.TreeMap;
/*      */ import javax.swing.DefaultComboBoxModel;
/*      */ import javax.swing.GroupLayout;
/*      */ import javax.swing.GroupLayout.Alignment;
/*      */ import javax.swing.GroupLayout.ParallelGroup;
/*      */ import javax.swing.GroupLayout.SequentialGroup;
/*      */ import javax.swing.JButton;
/*      */ import javax.swing.JComboBox;
/*      */ import javax.swing.JInternalFrame;
/*      */ import javax.swing.JLabel;
/*      */ import javax.swing.JPanel;
/*      */ import javax.swing.JRootPane;
/*      */ import javax.swing.JTextField;
/*      */ import javax.swing.LayoutStyle.ComponentPlacement;
/*      */ 
/*      */ class PortSelect extends JInternalFrame
/*      */ {
/*      */   private boolean SSH;
/*      */   private TopLevelGUI TLGUI;
/*      */   private DefaultComboBoxModel portListingModel;
/*      */   private DefaultComboBoxModel connectionDirectoryModel;
/* 1248 */   private int offset = 25;
/* 1249 */   private boolean fromConnectionDirectory = false;
/*      */   private JButton ConfirmButton;
/*      */   private JButton ManualButton;
/*      */   private JComboBox PortListingComboBox;
/*      */   private JComboBox ConnectionDirectoryComboBox;
/*      */   private JLabel PortSelectLabel;
/*      */   private JLabel OrLabel;
/*      */   private JPanel jPanel1;
/*      */   private JTextField PortEntryBox;
/*      */ 
/*      */   public PortSelect(TopLevelGUI TLGUI, boolean SSH, int multiplier)
/*      */   {
/* 1260 */     super("Available Ports", false, true, false, true);
/*      */ 
/* 1266 */     this.SSH = SSH;
/* 1267 */     this.TLGUI = TLGUI;
/*      */ 
/* 1269 */     this.portListingModel = new DefaultComboBoxModel();
/* 1270 */     this.connectionDirectoryModel = new DefaultComboBoxModel();
/*      */ 
/* 1272 */     initComponents();
/*      */ 
/* 1274 */     setLocation(this.offset * multiplier, this.offset * multiplier);
/*      */   }
/*      */ 
/*      */   private void initComponents()
/*      */   {
/* 1281 */     this.jPanel1 = new JPanel();
/* 1282 */     this.OrLabel = new JLabel();
/* 1283 */     this.PortSelectLabel = new JLabel();
/* 1284 */     this.PortEntryBox = new JTextField();
/* 1285 */     this.PortListingComboBox = new JComboBox();
/* 1286 */     this.ConnectionDirectoryComboBox = new JComboBox();
/* 1287 */     this.ConfirmButton = new JButton();
/* 1288 */     this.ManualButton = new JButton();
/*      */ 
/* 1290 */     setDefaultCloseOperation(2);
/*      */ 
/* 1292 */     setFrameIcon(this.TLGUI.titleBarIcon);
/*      */ 
/* 1294 */     this.jPanel1.setBackground(TopLevelGUI.windowBackground);
/* 1295 */     this.jPanel1.setForeground(TopLevelGUI.windowText);
/*      */ 
/* 1297 */     this.PortSelectLabel.setForeground(TopLevelGUI.windowText);
/* 1298 */     if (this.SSH)
/*      */     {
/* 1300 */       this.PortSelectLabel.setText("Please Enter the Desired Hostname or IP Address:");
/* 1301 */       this.ManualButton.setVisible(false);
/*      */     }
/*      */     else
/*      */     {
/* 1305 */       this.PortSelectLabel.setText("Please Enter the Desired Port:");
/*      */     }
/*      */ 
/* 1308 */     this.OrLabel.setForeground(TopLevelGUI.windowText);
/* 1309 */     this.OrLabel.setText("Or Select the Desired Port from the Connection Directory:");
/*      */ 
/* 1311 */     this.PortEntryBox.setText("");
/* 1312 */     this.PortEntryBox.setVisible(true);
/*      */ 
/* 1314 */     this.PortListingComboBox.setModel(this.portListingModel);
/* 1315 */     this.PortListingComboBox.setVisible(false);
/*      */ 
/* 1317 */     this.ConnectionDirectoryComboBox.setModel(this.connectionDirectoryModel);
/*      */ 
/* 1319 */     updateConnectionDirectory();
/*      */ 
/* 1321 */     this.ConfirmButton.setBackground(TopLevelGUI.buttonBackground);
/* 1322 */     this.ConfirmButton.setForeground(TopLevelGUI.buttonText);
/* 1323 */     this.ConfirmButton.setText("Confirm");
/* 1324 */     this.ConfirmButton.addActionListener(new ActionListener() {
/*      */       public void actionPerformed(ActionEvent evt) {
/* 1326 */         PortSelect.this.ConfirmEvent(evt);
/*      */       }
/*      */     });
/* 1330 */     getRootPane().setDefaultButton(this.ConfirmButton);
/*      */ 
/* 1332 */     this.ManualButton.setBackground(TopLevelGUI.buttonBackground);
/* 1333 */     this.ManualButton.setForeground(TopLevelGUI.buttonText);
/* 1334 */     this.ManualButton.setText("Scan Ports");
/* 1335 */     this.ManualButton.setEnabled(!this.SSH);
/* 1336 */     this.ManualButton.addMouseListener(new MouseAdapter() {
/*      */       public void mouseReleased(MouseEvent evt) {
/* 1338 */         PortSelect.this.ManualEvent(evt);
/*      */       }
/*      */     });
/* 1342 */     GroupLayout jPanel1Layout = new GroupLayout(this.jPanel1);
/* 1343 */     this.jPanel1.setLayout(jPanel1Layout);
/* 1344 */     jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false).addComponent(this.PortListingComboBox, GroupLayout.Alignment.LEADING, 0, -1, 32767).addComponent(this.ConnectionDirectoryComboBox, GroupLayout.Alignment.LEADING, 0, -1, 32767).addComponent(this.PortEntryBox, GroupLayout.Alignment.LEADING).addComponent(this.OrLabel, GroupLayout.Alignment.LEADING, -1, 275, 32767).addComponent(this.PortSelectLabel, GroupLayout.Alignment.LEADING, -1, 275, 32767)).addContainerGap(-1, 32767)).addGroup(GroupLayout.Alignment.CENTER, jPanel1Layout.createSequentialGroup().addComponent(this.ManualButton, -2, 134, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.ConfirmButton, -2, 134, -2)));
/*      */ 
/* 1361 */     jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(this.PortSelectLabel).addContainerGap(5, 32767).addComponent(this.PortEntryBox, -2, -1, 32767).addComponent(this.PortListingComboBox, -2, -1, 32767).addContainerGap(5, 32767).addComponent(this.OrLabel, -2, -1, 32767).addContainerGap(5, 32767).addComponent(this.ConnectionDirectoryComboBox, -2, -1, 32767).addContainerGap(5, 32767).addGroup(jPanel1Layout.createParallelGroup().addComponent(this.ConfirmButton, -2, -1, 32767).addComponent(this.ManualButton, -2, -1, 32767)).addContainerGap(5, 32767)));
/*      */ 
/* 1380 */     GroupLayout layout = new GroupLayout(getContentPane());
/* 1381 */     getContentPane().setLayout(layout);
/* 1382 */     layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jPanel1, -2, -1, 32767));
/*      */ 
/* 1386 */     layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jPanel1, -2, -1, 32767));
/*      */ 
/* 1391 */     pack();
/*      */   }
/*      */ 
/*      */   private void ConfirmEvent(ActionEvent e)
/*      */   {
/* 1398 */     if (this.SSH)
/* 1399 */       this.TLGUI.createSSHFrame(getChosenPortName(), this.fromConnectionDirectory);
/*      */     else {
/* 1401 */       this.TLGUI.createSerialPortFrame(getChosenPortName(), this.fromConnectionDirectory);
/*      */     }
/* 1403 */     dispose();
/*      */   }
/*      */ 
/*      */   private void ManualEvent(MouseEvent e)
/*      */   {
/* 1410 */     if (this.PortEntryBox.isVisible())
/*      */     {
/* 1412 */       this.ManualButton.setEnabled(false);
/* 1413 */       new Thread() {
/*      */         public void run() {
/* 1415 */           PortSelect.this.getPortListing();
/*      */         }
/*      */       }
/* 1413 */       .start();
/*      */ 
/* 1418 */       this.PortEntryBox.setText("Scanning...");
/* 1419 */       this.PortEntryBox.setEnabled(false);
/* 1420 */       this.ManualButton.setText("Manual Entry");
/* 1421 */       this.PortSelectLabel.setText("Please Select the Desired Port from the Available Ports:");
/*      */     }
/*      */     else
/*      */     {
/* 1425 */       this.PortSelectLabel.setText("Please Enter the Desired Port:");
/* 1426 */       this.PortEntryBox.setVisible(true);
/* 1427 */       this.PortListingComboBox.setVisible(false);
/* 1428 */       this.ManualButton.setText("Scan Ports");
/*      */     }
/*      */   }
/*      */ 
/*      */   public void getPortListing() {
/* 1436 */     this.portListingModel.removeAllElements();
/* 1437 */     this.portListingModel.addElement("Available Ports:");
/*      */     String[] thePorts;
/*      */     try {
/* 1442 */       thePorts = SerialPortLocal.getPortList();
/*      */     }
/*      */     catch (Exception e)
/*      */     {
/* 1446 */       thePorts = new String[0];
/*      */     }
/*      */ 
/* 1450 */     for (int x = 0; x < thePorts.length; x++)
/*      */     {
/* 1452 */       this.portListingModel.addElement(thePorts[x]);
/*      */     }
/*      */ 
/* 1455 */     this.PortEntryBox.setVisible(false);
/* 1456 */     this.PortListingComboBox.setVisible(true);
/* 1457 */     this.ManualButton.setEnabled(true);
/* 1458 */     this.PortEntryBox.setEnabled(true);
/* 1459 */     this.PortEntryBox.setText("");
/*      */   }
/*      */ 
/*      */   public String getChosenPortName()
/*      */   {
/* 1467 */     String name = "";
/*      */     try
/*      */     {
/* 1471 */       if (!this.PortListingComboBox.getSelectedItem().toString().equals("Available Ports:")) {
/* 1472 */         name = this.PortListingComboBox.getSelectedItem().toString();
/*      */       }
/*      */     }
/*      */     catch (Exception e)
/*      */     {
/*      */     }
/*      */     try
/*      */     {
/* 1480 */       if (!this.ConnectionDirectoryComboBox.getSelectedItem().toString().equals("Connection Directory:"))
/*      */       {
/* 1482 */         name = ((String[])TopLevelGUI.ConnectionDirectory.get(this.ConnectionDirectoryComboBox.getSelectedItem().toString()))[0];
/* 1483 */         this.fromConnectionDirectory = true;
/*      */       }
/*      */ 
/*      */     }
/*      */     catch (Exception e)
/*      */     {
/*      */     }
/*      */ 
/* 1491 */     if (name.equals("")) {
/* 1492 */       name = this.PortEntryBox.getText();
/*      */     }
/* 1494 */     return name;
/*      */   }
/*      */ 
/*      */   public void updateConnectionDirectory()
/*      */   {
/* 1501 */     this.connectionDirectoryModel.removeAllElements();
/* 1502 */     Object[] temp = TopLevelGUI.ConnectionDirectory.keySet().toArray();
/* 1503 */     this.connectionDirectoryModel.addElement("Connection Directory:");
/* 1504 */     for (int x = 0; x < temp.length; x++)
/*      */     {
/* 1506 */       this.connectionDirectoryModel.addElement((String)temp[x]);
/*      */     }
/*      */   }
/*      */ }

/* Location:           F:\6-30-2012\Hazell\
 * Qualified Name:     hmc.PortSelect
 * JD-Core Version:    0.6.0
 */